// pages/coupon/coupon.js
//获取应用实例
var app = getApp()
var utils = require('../../utils/util.js');
Page({
  /*** 页面的初始数据 */
  data: {
    // 选项卡
    winWidth: 0,
    winHeight: 0,
    // tab切换  
    currentTab: 0,
    // 商品内容数据
    carts: [],
  },
  /** * 滑动切换tab  */
  bindChange: function (e) {
    var that = this;
    that.setData({ currentTab: e.detail.current });
  },
  /** * 点击tab切换  */
  swichNav: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  /*** 生命周期函数--监听页面加载*/
  onLoad: function (options) {
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    var sucFunc = function (that, res) {
      that.setData({
        cartsW: res.data.cartsW,
        cartsY: res.data.cartsY,
        cartsG: res.data.cartsG,
        imgPath: app.d.imgPath
      })
      wx.hideLoading();
    }
    var data = { openid: app.d.openid }
    utils.wxRequest(that, app.d.path, "My/coupon", data, sucFunc);
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          clientHeight: res.windowHeight
        });
      }
    });
  },
  /*** 生命周期函数--监听页面显示*/ 
  onShow: function () {
    if (app.globalData.currentLocation == '') {
      this.setData({
        currentTab: 0
      });
    } else {
      var i = app.globalData.currentLocation;
      this.setData({
        currentTab: i
      });
    }
  },
  detail:function(e){
    var that = this;
    var id = e.currentTarget.id;
    wx.navigateTo({
      url: '/pages/couponDetail/couponDetail?id=' + id
    })
  }
})